
             
/**
 * Copyright (c) 2012-2013 JLLT Corp. 2012-2013,All Rights Reserved.
 * This software is published under the 金麟龙腾商贸有限公司.
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 * 
 * @File name:  UpdateTPersonnalAction.java   【员工信息:T_PERSONNAL】
 * @Create on:  2012-06-25 21:11:292
 * @Author   :  陈伟
 * @Copyright 
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */

           
        

package com.boho.ecp.deposit.staff.action;

            
import java.sql.Connection;

import cn.boho.framework.actions.ActionImp;
import cn.boho.framework.context.ActionContext;
import cn.boho.framework.exception.UserOperationException;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.service.MessageService;

import com.boho.ecp.constant.Staff;
import com.boho.ecp.deposit.staff.dao.TPersonnalDao;
            
        
public class StaffLoginAction extends ActionImp {
	private Connection con = null;
	private String personnalNo = "";
	private String password = "";
	@Override
	protected void doException(ActionContext atx, Exception ex) {
		if (!(ex instanceof UserOperationException)) {
			atx.setErrorContext("STAFF_LOGIN_FAIL", MessageService.getMessage("STAFF_LOGIN_FAIL"),"员工登录" ,ex);
		}
	}
	@Override
	protected int performExecute(ActionContext atx) throws Exception {
		con = atx.getConection();
		DynaBeanMap dbm = TPersonnalDao.getTPersonnalByPersonnalNo(con, personnalNo);
		if(dbm == null){
			UserOperationException uoe = new UserOperationException();
			atx.setErrorContext("STAFF_LOGIN_NOT_EXIST", MessageService.getMessage("STAFF_LOGIN_NOT_EXIST"), uoe);
			throw uoe;
		}
		else{
			String dbmPwd = (String)dbm.get("PERSONNAL_PWD");
			if(!dbmPwd.equals(password)){
				UserOperationException uoe = new UserOperationException();
				atx.setErrorContext("STAFF_LOGIN_PWD_ERROR", MessageService.getMessage("STAFF_LOGIN_PWD_ERROR"), uoe);
				throw uoe;
			}
			else{
				atx.setSessionValue(Staff.STAFF_SESSION_NO, (String)dbm.get("PERSONNAL_NO"));
				atx.setSessionValue(Staff.STAFF_SESSION, dbm);
				atx.setValue("STAFF", dbm);
			}
		}
		return 1;
	}
	@Override
	protected int verifyParameters(ActionContext atx) throws Exception {
		personnalNo = atx.getStringValue("PERSONNAL_NO");
		password = atx.getStringValue("PASSWORD");
		return 1;
	}
}
